﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Homework_9th
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 调用网页获取类获取输入的url网页内容，
        /// 使用正则表达式类截取出电话号码和邮箱地址
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            string url = textBoxURL.Text;
            try
            {
                string content = GetWebPage.getPage(url);
                List<string> emailList = RegularExpOp.getEmail(content);
                List<string> phoneList = RegularExpOp.getPhone(content);
                string emailStr = "";
                string phoneStr = "";
                if (emailList != null && emailList.Count > 0)
                    foreach (string email in emailList)
                        emailStr += email+"\r\n";
                if (phoneList != null && phoneList.Count > 0)
                    foreach (string phone in phoneList)
                        phoneStr += phone+"\r\n";
                textBoxEmail.Text = emailStr;
                textBoxPhone.Text = phoneStr;
            }
            catch (ReadException rex)
            {
                textBoxEmail.Text = rex.ToString();
                textBoxPhone.Text = rex.ToString();
            }
        }
    }
}
